**************************************************************************************************************
**	Replication do-file for "Governmment Policies and the Emergence of an Ethnic Dimension in Party Systems"
**	Author: Maayan Mor
**	Purpose: calculate the share of Zentrum and Catholic delegates 1849-1874. 
**	Run this code before producing Figure 1.
**************************************************************************************************************
clear all
set more off

/* SET DIRECTORY */

/***************************************************
Calculate the number of Catholic delegates 1867-1874
***************************************************/
use "S8006.dta", clear

** religion
recode v24 (2=1) (1 3/9=0)
label define v24 0 "non-catholic" 1 "catholic", modify
label val v24 v24
rename v24 r_

** districts
rename v29 cst_1865  // the elections of February 1867
rename v30 cst_1866  // the elections of August 1867 
rename v31 cst_1871
rename v32 cst_1874

** Reshape the data file
keep  id1 name vname r_ cst_1865 cst_1866 cst_1871 cst_1874
reshape long el_ cst_, i(id1) j(year)

**	Assign constituency ID
rename cst_ v30_best_code
merge m:1 v30_best_code using "Best Haege cst numbers.dta", keepusing(drunno_haege)

** drop the districts that were not in Prussia in 1864. 
keep if drunno_haege<237 | drunno_haege==0  /* not in Prussia */
drop if drunno_haege==236 					/* Sigmaringen    */
drop if drunno_haege>150 & drunno_haege<170 /* Hannover       */
drop if drunno_haege>186 & drunno_haege<201 /* Hesse-nassau   */
drop if drunno_haege>140 & drunno_haege<151 /* Schleswig-holstein*/

drop _merge v30_best_code name vname id1

gen space="_"
egen cst_year=concat(drunno_haege space year)

collapse (sum) r_, by(cst_year)

split cst_year, p("_")
rename cst_year2 year
destring year, replace
	
** Prepare this file to be merged to generate Figure 1
gen count=1
egen total_rt=total(count), by(year) /* the number of Reichstag seats */
egen total_r=total(r_==1), by(year)
gen share_catholics=(total_r/total_rt)*100
duplicates drop year, force
replace year=1867  if year==1865
replace year=1868  if year==1866

keep share_catholics year

save "number of Catholics 1867-1874.dta", replace

/**************************************************
** 		Calculate the number of Catholic delegates
***************************************************/
use "biographies 49-67.dta", clear
drop DM_t id_empty id

recode year (48=1848)(49=1849) (52=1852) (55=1855) (58=1858) (61=1861) ///
(62=1862) (63=1863) (66=1866) 

reshape wide r_ p_ , i(Kuehne_ID) j(year)

foreach x of numlist 1848 1849 1852 1855 1858 1861 1862 1863 1866{
egen catholics_`x'=total(r_`x')
}

keep catholics_*
keep in 1

xpose, clear
rename v1 no_catholics

gen year=1848  // JANUARY  1849
replace year=1849 in 2 // JULY 1849.5
replace year=1852 in 3
replace year=1855 in 4
replace year=1858 in 5
replace year=1861 in 6
replace year=1862 in 7
replace year=1863 in 8
replace year=1866 in 9

gen share_catholics=(no_catholics/256)*100

keep share_catholics year
append using "number of Catholics 1867-1874.dta"
save "Catholic delegates.dta", replace 

/**************************************************
** 		Calculate the number of Zentrum delegates
***************************************************/
use "state long.dta", clear

egen share_zentrum=total(p_), by(year)
replace share_zentrum=(share_zentrum/256)*100
keep year share_zentrum
duplicates drop _all, force

set obs 14
replace year=1871 in 13
replace year=1874 in 14

sort year
merge 1:1 year using "Catholic delegates.dta", nogen
replace share_zentrum=. if year==1848 /*the Zentrum did not exist in 1848*/ 
replace share_zentrum=. if year==1849 /*the Zentrum did not exist in 1848*/ 
replace share_zentrum=. if year==1867 /*the Zentrum did not exist in 1867; 
those are MP that were associated with the party in the 1860s and 1870s*/

replace year=1849.5 if year==1849
replace year=1849   if year==1848
replace year=1867.8 if year==1868
sort year

save "Catholic Zentrum delegates.dta", replace

